package controllers

import (
	"Mountian/btc"
	"Mountian/models"
	"fmt"
	"github.com/astaxie/beego"
	"strconv"
)

type TransactionController struct {
	beego.Controller
}

//检查地址属性
// @router /unsign [post]
func (c *TransactionController) Unsign() {

	var ret models.Response
	ret.Data = ""

	Unspent := c.GetString("Unspent")

	Symbol := c.GetString("Symbol")
	From := c.GetString("From")
	To := c.GetString("To")
	Amount, err0 := strconv.ParseFloat(c.GetString("Amount"), 64)
	Fee, err1 := strconv.ParseFloat(c.GetString("Fee"), 64)
	fmt.Println(Unspent,Symbol,From,To,Amount,Fee)
	if err0 != nil ||err1 != nil || Symbol == "" || Unspent == "" ||From == "" || To == "" || Amount <= 0 || Fee <= 0{
		ret.Code = 1
		ret.Msg = "获取待签名串失败,参数错误"
		c.Data["json"] = ret
		c.ServeJSON()
		return
	}
	if Symbol == "BTC" {
		unsign,err := btc.GetUnSign(Unspent,From,To,int64(Amount*100000000.0),int64(Fee*100000000.0))
		if err != nil {
			ret.Code = 1
			ret.Msg = "获取待签名串失败," + err.Error()
			c.Data["json"] = ret
			c.ServeJSON()
			return
		}else {
			ret.Code = 0
			ret.Data = unsign
			c.Data["json"] = ret
			c.ServeJSON()
			return
		}
	}else {
		ret.Code = 1
		ret.Msg = "获取待签名串失败,币种暂未支持"
		c.Data["json"] = ret
		c.ServeJSON()
		return
	}
	c.Data["json"] = ret
	c.ServeJSON()
	return

}
